clear;clc

load P00Data;

Names=cell(4,2);
Names{1,1} = 'Results_Simple_M'; Names{2,1} = 'Results_Simple_Q'; Names{3,1} = 'Results_Simple_ADec'; Names{4,1} = 'Results_Simple_AJun';
Names{1,2} = 'Results_Log_M'; Names{2,2} = 'Results_Log_Q'; Names{3,2} = 'Results_Log_ADec'; Names{4,2} = 'Results_Log_AJun';

MULT = [1200 400 100 100];
for freq = 1:4
    for ct = 2:-1:1
        load('ResultsFile',Names{freq,ct}); Results = eval(Names{freq,ct});

        if ct == 1
            load BootAllResults11; % Full-sample, simple returns
        else
            load BootAllResults12; % Full-sample, log returns
        end
        switch freq
            case 1, AllBootStatsIS = AllBootStatsIS_M; AllBootStatsOOS = AllBootStatsOOS_M;
            case 2, AllBootStatsIS = AllBootStatsIS_Q; AllBootStatsOOS = AllBootStatsOOS_Q;
            case 3, AllBootStatsIS = AllBootStatsIS_ADec; AllBootStatsOOS = AllBootStatsOOS_ADec;
            case 4, AllBootStatsIS = AllBootStatsIS_AJun; AllBootStatsOOS = AllBootStatsOOS_AJun;
        end

        for i = 1:46
            if freq==1 && ~strcmp(VARS(i).Freq,'Monthly')
                continue;
            elseif freq==2 && (strcmp(VARS(i).Freq,'Annual') || strcmp(VARS(i).Freq,'Semiannual'))
                continue;
            end
            fprintf('%d %d %d %d ',VARS(i).PaperNum, Results(i).SampleBeg, Results(i).SampleEnd, Results(i).OOSBeg);

            fprintf('%.2f %.2f %.2f ',100*Results(i).ISStats.R2, 100*Results(i).ISStats.beta, Results(i).ISStats.tNwest);
            Act = Results(i).ISStats.tNwest;
            absAct = abs(Act);
            Boot = extractfield(AllBootStatsIS(:,i),'tNwest')';
            Bpval = (sum(Boot>=absAct) + sum(Boot<=-absAct)) / sum(isfinite(Boot));  % 2-sided
            fprintf('%.2f ',Bpval);

            fprintf('%.2f %.2f ',100*Results(i).ISStats.KMSSlope, Results(i).ISStats.KMSp);

            for ii = 1:3
                fprintf('%.2f %.2f ',100*Results(i).ISStats.betaSplit(ii),Results(i).ISStats.tNwestSplit(ii));
            end

            fprintf('%.2f %.2f ',100*Results(i).OOSStats.R2, 100*Results(i).OOSStats.DMAE);

            Stat = Results(i).OOSStats.MSEF;
            fprintf('%.2f ',Stat(1));
            if Stat(1)>=Stat(4); fprintf('*** '); elseif Stat(1)>=Stat(3); fprintf('** '); elseif Stat(1)>=Stat(2); fprintf('* '); else; fprintf('NS '); end
            Act = Stat(1);
            Boot = extractfield(AllBootStatsOOS(:,i),'MSEF')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f ', Bpval);
            
            Stat=Results(i).OOSStats.ENCF;
            fprintf('%.2f ',Stat(1));
            if Stat(1)>=Stat(4); fprintf('*** '); elseif Stat(1)>=Stat(3); fprintf('** '); elseif Stat(1)>=Stat(2); fprintf('* '); else; fprintf('NS '); end
            Act = Stat(1);
            Boot = extractfield(AllBootStatsOOS(:,i),'ENCF')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f ', Bpval);

            fprintf('%.2f ',Results(i).OOSStats.ENClambd);
            
            fprintf('%.2f %.2f ',100*Results(i).OOSStats.R2_CT,100*Results(i).OOSStats.DMAE_CT);

            Stat=Results(i).OOSStats.MSEF_CT;
            fprintf('%.2f ',Stat(1));
            if Stat(1)>=Stat(4); fprintf('*** '); elseif Stat(1)>=Stat(3); fprintf('** '); elseif Stat(1)>=Stat(2); fprintf('* '); else; fprintf('NS '); end
            Act = Stat(1);
            Boot = extractfield(AllBootStatsOOS(:,i),'MSEF_CT')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f ', Bpval);
            
            Stat=Results(i).OOSStats.ENCF_CT;
            fprintf('%.2f ',Stat(1));
            if Stat(1)>=Stat(4); fprintf('*** '); elseif Stat(1)>=Stat(3); fprintf('** '); elseif Stat(1)>=Stat(2); fprintf('* '); else; fprintf('NS '); end
            Act = Stat(1);
            Boot = extractfield(AllBootStatsOOS(:,i),'ENCF_CT')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f ', Bpval);

            fprintf('%.2f ',Results(i).OOSStats.ENClambd_CT);
            
            fprintf('%.2f %.2f ',MULT(freq)*(Results(i).OOSStats.UtilMdl-Results(i).OOSStats.UtilUnc), Results(i).OOSStats.tDiffUtil(1));
            Act = Results(i).OOSStats.tDiffUtil(1);
            Boot = extractfield(AllBootStatsOOS(:,i),'DiffUtil1t')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f ',Bpval);

            fprintf('%.2f %.2f ',MULT(freq)*(Results(i).OOSStats.UtilMdl-Results(i).OOSStats.UtilMkt), Results(i).OOSStats.tDiffUtil(2));
            Act = Results(i).OOSStats.tDiffUtil(2);
            Boot = extractfield(AllBootStatsOOS(:,i),'DiffUtil2t')';
            Bpval = sum(Boot>=Act) / sum(isfinite(Boot));
            fprintf('%.2f\n',Bpval);
        end
        disp(' ');
    end
    disp(' ');
end